package cc.wsyw126.java.nowcoder.offernet;

/**
 * Created by dp on 17/3/25.
 */

import java.util.LinkedList;
import java.util.Scanner;

public class net3 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        LinkedList<String> list = new LinkedList<>();
        int length = s.length();
        for (int i = 0; i < length; i++) {
            list.add(String.valueOf(s.charAt(i)));
        }

        String first = list.get(0);
        int count = 0;
        int sum = 0;
        for (int i = 0; i < length; i++) {
            if (list.get(i).equals(first)) {
                count++;
            } else {
                sum+=count;
            }
        }

        int j = length;
        for (int i = 0; i < length; i++) {
            if (list.get(i).equals(first)) {
                continue;
            } else {
                j=i;
                break;
            }
        }

        count=0;
        int sum1= 0;
        for (int i = j; i < length; i++) {
            if (!list.get(i).equals(first)) {
                count++;
            } else {
                sum1+=count;
            }
        }

        System.out.println(sum>sum1?sum1:sum);

    }
}